package com.chen.pojo.bean;

import cn.hutool.core.date.DateUtil;
import com.chen.pojo.User;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.ObjectUtils;

import java.util.Date;


@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserInfo {
    private int id;
    private String username;
    private String nick;
    private int age;
    private String sex;
    private String address;
    private String avatar;
    private int role;
    private int status;

    private String regtime;
    private Long token;
    private String introduce;


    public UserInfo(User user) {
        this.id = user.getId();
        this.age = user.getAge();
        this.sex = user.getSex();
        this.address = user.getAddress();
        this.role = user.getRole();
        this.username = user.getUsername();
        //this.avatar = user.getAvatar();
        this.nick = user.getNick();
        this.status = user.getStatus();
        // 这里处理空指针异常
        if (ObjectUtils.isEmpty(user.getRegtime())) {
            this.regtime = "";
        } else {
            this.regtime = DateUtil.format(user.getRegtime(), "yyyy-MM-dd HH:mm:ss");
        }
        this.avatar = user.getAvatar() != null ? user.getAvatar() : "https://img2.baidu.com/it/u=2285567582,1185119578&fm=26&fmt=auto";
        this.introduce = user.getIntroduce() != null ? user.getIntroduce() : "介绍一下自己吧";

    }


}
